From patchwork Wed Mar 30 17:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1611269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=D0hWOZZJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTDT715gMz9sBJ for ; Thu, 31 Mar 2022 04:49:13 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nZcRL-00065k-7B; Wed, 30 Mar 2022 17:49:03 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nZcRJ-00065F-1Q for kernel-team@lists.ubuntu.com; Wed, 30 Mar 2022 17:49:01 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C73763F8D4 for ; Wed, 30 Mar 2022 17:49:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1648662540; bh=rQ80khXoyVhplGlUbcwHHepqBgI8ZwdNUqw4gMW7isM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=D0hWOZZJMsEkdFf8njTf7wtuZCWoz9ADswjr3J0qaTKs/Ui8ElhfaSLnF+4/Q7Dfx 0cGKHcPO6iHzwtJqWD64ySpp58hH4191hX62QMfJ4cBseNVOkH0mOZk9Tw54DLfb0F 8+JySRHaWhT3ghrcuXtkSgUBDa1yB3+cpufDcV7Mp6LdlbTuO/y+9izAbqKzU3oX/j uqyh6WsmvDFSlAuDCBBlVjJklnfBGZouhcNogNIEbEOnua7nYDk2yp2ia38Nmn+z/i 6j3KXHIsSB5h5yfUs+X8MfUbC5xkwvBWkI7C+ULrqjuaniJmmX+qug/LoDq2lir2WM FgA7LkWplnUqw== Received: by mail-pg1-f197.google.com with SMTP id t24-20020a632258000000b003988eed18b2so2792876pgm.22 for ; Wed, 30 Mar 2022 10:49:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rQ80khXoyVhplGlUbcwHHepqBgI8ZwdNUqw4gMW7isM=; b=0xQmDfZDXvJKATuRJOONIglN7yhH3kQM5VsG+16iDYAJfVPCYWo80LJR4GjDDgyOpZ Mrk7jVjI8/2klkjKGou1YWJASZVATWqLE6UNSmWQrEPpFvJL2wQrbpUPbh1A6hYW7ciL XeN2lhhbbAkUagVxwKzqjNehmZOuJMrRL/J05uW7oxFSnsknZ5MoQL4sArSN+SKHMY3C QNaFVYnoDJKz5gLaAyzy6FjLK7OSZm/d0mknCIlzLunJOhSfHIORjb1dYwmKN4gSLwkh VABx64QmRpvmhiUPr42gyWurp2cXfR+uWew410UCXr1V7n+bsOJQotHNvC3lsrJ7nVNc NHOw== X-Gm-Message-State: AOAM532smUDCCD+3gE/83h5mIq6p6fik1dAOVl2QfzbQeZCUw5idSb/R yE7bEWoEnyRmzsUvb5/wRaFeKOD2733z6GdSyEUFcdJaPATJFTR/RAp8QddSDbDJZnA9bYf85S9 GAJiR5+Mo5GDddaUIb7kmZJ0bcg5X8zX2qbN0xswlEg== X-Received: by 2002:a17:903:120c:b0:154:c135:60d3 with SMTP id l12-20020a170903120c00b00154c13560d3mr811294plh.48.1648662537806; Wed, 30 Mar 2022 10:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzn8alrqU5jAT+1Dux3QmqXAe0pZLDEPbvnqkywIPUI2k4zxiOeyWaadF2Fz83hUm8RZYT6jQ== X-Received: by 2002:a17:903:120c:b0:154:c135:60d3 with SMTP id l12-20020a170903120c00b00154c13560d3mr811252plh.48.1648662537322; Wed, 30 Mar 2022 10:48:57 -0700 (PDT) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id c18-20020a056a000ad200b004cdccd3da08sm25393453pfl.44.2022.03.30.10.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 10:48:56 -0700 (PDT) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] UBUNTU: SAUCE: azure: Swiotlb: Add swiotlb_alloc_from_low_pages switch Date: Wed, 30 Mar 2022 11:48:52 -0600 Message-Id: <20220330174852.24537-1-tim.gardner@canonical.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Tianyu Lan BugLink: https://bugs.launchpad.net/bugs/1967166 Hyper-V Isolation VM and AMD SEV VM uses swiotlb bounce buffer to share memory with hypervisor. Current swiotlb bounce buffer is only allocated from 0 to ARCH_LOW_ADDRESS_LIMIT which is default to 0xffffffffUL. Isolation VM and AMD SEV VM needs 1G bounce buffer at most. This will fail when there is not enough memory from 0 to 4G address space and devices also may use memory above 4G address space as DMA memory. Expose swiotlb_alloc_from_low_pages and platform mey set it to false when it's not necessary to limit bounce buffer from 0 to 4G memory. Signed-off-by: Tianyu Lan Signed-off-by: Tim Gardner --- This patch depends on a previous pull request: [Pull Request] [impish/linux-azure] Azure: Update Hyperv to 5.17 --- include/linux/swiotlb.h | 1 + kernel/dma/swiotlb.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 2356da25c3b9..037356d57abf 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -38,6 +38,7 @@ enum swiotlb_force { extern void swiotlb_init(int verbose); int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose); unsigned long swiotlb_size_or_default(void); +void swiotlb_set_alloc_from_low_pages(bool low); extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); extern int swiotlb_late_init_with_default_size(size_t default_size); extern void __init swiotlb_update_mem_attributes(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index c57e78071143..e2c1395740de 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -67,6 +67,7 @@ enum swiotlb_force swiotlb_force; struct io_tlb_mem *io_tlb_default_mem; phys_addr_t swiotlb_unencrypted_base; +static bool swiotlb_alloc_from_low_pages = true; /* * Max segment that we can provide which (if pages are contingous) will @@ -109,6 +110,11 @@ void swiotlb_set_max_segment(unsigned int val) max_segment = rounddown(val, PAGE_SIZE); } +void swiotlb_set_alloc_from_low_pages(bool low) +{ + swiotlb_alloc_from_low_pages = low; +} + unsigned long swiotlb_size_or_default(void) { return default_nslabs << IO_TLB_SHIFT; @@ -253,8 +259,15 @@ swiotlb_init(int verbose) if (swiotlb_force == SWIOTLB_NO_FORCE) return; - /* Get IO TLB memory from the low pages */ - tlb = memblock_alloc_low(bytes, PAGE_SIZE); + /* + * Get IO TLB memory from the low pages if swiotlb_alloc_from_low_pages + * is set. + */ + if (swiotlb_alloc_from_low_pages) + tlb = memblock_alloc_low(bytes, PAGE_SIZE); + else + tlb = memblock_alloc(bytes, PAGE_SIZE); + if (!tlb) goto fail; if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))