From nobody Sun Jun 28 09:36:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0B81C433F5 for ; Wed, 9 Feb 2022 12:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbiBIMXh (ORCPT ); Wed, 9 Feb 2022 07:23:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232671AbiBIMXZ (ORCPT ); Wed, 9 Feb 2022 07:23:25 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF65BC050CD2; Wed, 9 Feb 2022 04:23:26 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id j4so2038095plj.8; Wed, 09 Feb 2022 04:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hh4jMpg8FB1udogjbNB+Sii1QdXJESjYTwcDUY5y0oA=; b=cF+q4qc+10FcqXJ8k2pqRoWI7jFembF/aqdarCrJ1AO8/X3Oj/pMSLDWR3uFLaiqbx ogg4igUDarQ6aNTxpXknpQQdyqMlx2Ofte7Q3OUbMyCX8Zua829jgVwALeSVW+iY0Sbu N4AeJqVaOgXcus8bPtpRdjgBs4QLjAj3fSQ8fuCFMXa6yzpyGhHrDrf1WyQqQL4aSCi2 njAAlOijFTduqU6h/7zBbE3IRPqrsln+A+GHDRbn37vHXXPAUulgOyZQ9qbtzP0HN2L7 phuu7tbw6SxC6CvkqubBW9GD/UztSvCy+22LSQfLferlOFm0+21yNOO/FDVA1Y2khjCz nAvw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hh4jMpg8FB1udogjbNB+Sii1QdXJESjYTwcDUY5y0oA=; b=O//IJeyI1GqMDb8EFQgSNpzn+yTGO92YBNQ/Cl2herE2QGnESACeYpKc7bT/mT4xqY RVnw0NswOzPcXNeIAX/4tc7apWOBW3aK3AJq4zMqyc/QtlJj5LovUTt8t58wqnEhF2r5 nLaT7YMJelQS32NvqlJX8yE0sIakB0+ZIPNZaNu5/Vp4ESiTvRym411rAauJfhyKxX4g YsmfK+XYgyKihkNEFS2VRQMQip3rzIQfFhopUZsp8n0HdTDF/VzHypDUilZxbs6zIAKT JaYTuKOj6XYLAW/EGeOHJmS+PU0KHExI9AHMqJNWC1f3u3rk6wCU7r+gKqiV5kAEtGFG KzYQ== X-Gm-Message-State: AOAM531fBJAQ5xwdk+78yZDTXn8sxa+2GcV0W/XfrfGeMyS1+/fnjNrA yfOX8VD+sAkdbekE2QeuMrM= X-Google-Smtp-Source: ABdhPJwnZIrLHzT8/ZP+XssNQ0ZTkXO6ZjeqNb4h3vsPFa2mZJZ7cvEKT6w/iNJdXHcvAllSyeKYjg== X-Received: by 2002:a17:90b:4acb:: with SMTP id mh11mr2285572pjb.72.1644409406297; Wed, 09 Feb 2022 04:23:26 -0800 (PST) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:a:9d5c:32bf:5c81:da87]) by smtp.gmail.com with ESMTPSA id lb3sm6300990pjb.47.2022.02.09.04.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:23:26 -0800 (PST) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, michael.h.kelley@microsoft.com Cc: Tianyu Lan , iommu@lists.linux-foundation.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, brijesh.singh@amd.com, konrad.wilk@oracle.com, hch@lst.de, parri.andrea@gmail.com, thomas.lendacky@amd.com Subject: [PATCH V2 1/2] Swiotlb: Add swiotlb_alloc_from_low_pages switch Date: Wed, 9 Feb 2022 07:23:01 -0500 Message-Id: <20220209122302.213882-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209122302.213882-1-ltykernel@gmail.com> References: <20220209122302.213882-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Tianyu Lan 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 --- include/linux/swiotlb.h | 1 + kernel/dma/swiotlb.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index f6c3638255d5..2b4f92668bc7 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -39,6 +39,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 f1e7ea160b43..62bf8b5cc3e4 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -73,6 +73,8 @@ enum swiotlb_force swiotlb_force; =20 struct io_tlb_mem io_tlb_default_mem; =20 +static bool swiotlb_alloc_from_low_pages =3D true; + phys_addr_t swiotlb_unencrypted_base; =20 /* @@ -116,6 +118,11 @@ void swiotlb_set_max_segment(unsigned int val) max_segment =3D rounddown(val, PAGE_SIZE); } =20 +void swiotlb_set_alloc_from_low_pages(bool low) +{ + swiotlb_alloc_from_low_pages =3D low; +} + unsigned long swiotlb_size_or_default(void) { return default_nslabs << IO_TLB_SHIFT; @@ -284,8 +291,15 @@ swiotlb_init(int verbose) if (swiotlb_force =3D=3D SWIOTLB_NO_FORCE) return; =20 - /* Get IO TLB memory from the low pages */ - tlb =3D 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 =3D memblock_alloc_low(bytes, PAGE_SIZE); + else + tlb =3D memblock_alloc(bytes, PAGE_SIZE); + if (!tlb) goto fail; if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose)) --=20 2.25.1 From nobody Sun Jun 28 09:36:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D68DC433F5 for ; Wed, 9 Feb 2022 12:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232766AbiBIMXb (ORCPT ); Wed, 9 Feb 2022 07:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232089AbiBIMXZ (ORCPT ); Wed, 9 Feb 2022 07:23:25 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF318C05CBBF; Wed, 9 Feb 2022 04:23:27 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id u12so578306plf.13; Wed, 09 Feb 2022 04:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gHeTaNHwKSwgi47qQAMrwwvH4JdfELhdvY0tFE0Qdgg=; b=S4UvQ+/nM+8fNSw1PE4f+4FCLumVlciBxAOJ92AgHiZW5Ix90CFkrXBfCJanEy1u1i h327fu0yGbej2+hz5q+Zr0jyauX4+htYZAfhTLDCwNO2q1P4ImBDYBAkWo7RPHALengd kDUQWdymGHyVPMuDDkXrx08iNMBIZlw8riENN2e+BqMa+rRIHJdTVFbay4OuPv2cWXVJ Go/F0Wn7BvcSKRVOMdKi65o/pnm3jzVTWYQdyW5blerbNx580YsOv35CvZnKjZQwwd94 n94rOuGsjXEn3fK3r+Ugv5VolUI/8ppVsMa0ccRAf15Vg5NteIKxqt7svtTCD3RALfd7 MJCQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=gHeTaNHwKSwgi47qQAMrwwvH4JdfELhdvY0tFE0Qdgg=; b=HqBfLU4eyFcBrv477lhlO5aDb28ZNipZeJQeiA57EDzBCzHos6AlSHDZ2snqvtaRXH 6iFT/zrIEV2+gFqd4MKQ0M5Gabo3xQ7vZOobcgG52U48KCPwb9LUEgfpQYcDZBZgqqtJ QX1QBZk2CmD9j52XSjINoA4b9nsFa+bpjKC2JWIkpQnRE6YATXTruZ/YvTHlcZQkgQA5 /6velqeDks6bIhlk6HRW40rrMl8k/mZrH4YssakAbgkxmyrN9xMBqt0YplnrZ/o+SByt GwuPQOjDwEk98vovhSy1jZ7aLQsN8FEyIOXroe9oriebRqoUrAJbUR8CvmqbLrWDHX5F xIIQ== X-Gm-Message-State: AOAM533Gt8JW5NU25aT0S6xsK0xXqMrPX9hopegK7mU7mtQouB53xplq lFF0lFoSeNs31+BqV6hlAQk= X-Google-Smtp-Source: ABdhPJwVRhlS8xFIf1Zk17POR18zyrDa+Pemk4xck9NefmzGyh/YFa/RyzlAaK6sHR+JvpUJrSy0lg== X-Received: by 2002:a17:902:b185:: with SMTP id s5mr2181136plr.123.1644409407053; Wed, 09 Feb 2022 04:23:27 -0800 (PST) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:a:9d5c:32bf:5c81:da87]) by smtp.gmail.com with ESMTPSA id lb3sm6300990pjb.47.2022.02.09.04.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:23:26 -0800 (PST) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, michael.h.kelley@microsoft.com Cc: Tianyu Lan , iommu@lists.linux-foundation.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, brijesh.singh@amd.com, konrad.wilk@oracle.com, hch@lst.de, parri.andrea@gmail.com, thomas.lendacky@amd.com Subject: [PATCH V2 2/2] x86/hyperv: Make swiotlb bounce buffer allocation not just from low pages Date: Wed, 9 Feb 2022 07:23:02 -0500 Message-Id: <20220209122302.213882-3-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209122302.213882-1-ltykernel@gmail.com> References: <20220209122302.213882-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Tianyu Lan In Hyper-V Isolation VM, swiotlb bnounce buffer size maybe 1G at most and there maybe no enough memory from 0 to 4G according to memory layout. Devices in Isolation VM can use memory above 4G as DMA memory and call swiotlb_alloc_from_low_pages() to allocate swiotlb bounce buffer not limit from 0 to 4G. Signed-off-by: Tianyu Lan --- arch/x86/kernel/cpu/mshyperv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 5a99f993e639..50ba4622c650 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -343,6 +343,7 @@ static void __init ms_hyperv_init_platform(void) * use swiotlb bounce buffer for dma transaction. */ swiotlb_force =3D SWIOTLB_FORCE; + swiotlb_set_alloc_from_low_pages(false); #endif } =20 --=20 2.25.1