Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30645384rwd; Thu, 6 Jul 2023 08:43:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlGy4B5nrOdZd0bFqx/ZvoDAlFOEIVN+jOI1XvjmbnRnPAg3IdNKF8vYvy/K1qVOMo9xNAev X-Received: by 2002:a17:90a:7488:b0:263:5333:ca26 with SMTP id p8-20020a17090a748800b002635333ca26mr1655778pjk.29.1688658203408; Thu, 06 Jul 2023 08:43:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1688658203; cv=pass; d=google.com; s=arc-20160816; b=cMezkBr8Z0zZvVmf9YFw9NV3hXf3xOdZjnW7Sm9wJZDZgd8cTXna+2xn4x0QZR+cQG S8z+sqJ6vvYf2dO6/DjONlnCUZT4UbBuAdt9T2ed31XwicQ4Af29RDeWWGORSa1gE/pw aIflQzaiBvl4Zewpfpd86wNrwP4QiDrqlgeSemsb8tigwf1LkIGbw52qSzAK/b+2CF2u jfpImvkta8e0zVPqa1EsuN+4Nh3QKhhv0P494Um71UH6A1SB/mA3JQc/aDAqzUhCd3S2 bfi1DHWTZMTw8dewzf262h+fefhJWm5+w1UtzuOEe7gpsChOCxZQDmr46X22hOH+NLlI jX0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :msip_labels:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=wG+YaDqOerIORGaH0fUqy7utjqv7UUuWUSk817E/mzg=; fh=Q/U/zAtthBWaTsshqD7OIsCiq6Hk9GF/jw6eqkUcILk=; b=ii6JbhiJLjRj+5jY0ZXiv2hY1saH0/PpSA24dK2+CVZUN7yW8ogH11zHQC3IASMhiW ZRMrRSuuJeimmVy17iJBtyKSvlmdCdRf5CF2DFHBnyvMBCtZ4QV0b/Dg43cncEbwMwPx fJ/Wx2F9XxS57bGaEqpfHxIXNCv2vzw5lDeAdivO5jwDRxUr/yIvG+6os6kAxoOZRr+Q zLWmZTcZNiA7Rd6QWTA3BA0A3ewDlhehQH/JmS22mNW4WN/M8nYo4hMP3h5LKh0pWzaD I+CWcxDlHuHOBtiurhX1BR5dxEr5cyg1V7eKepTURXpKB2pzj3j0hmuBG9S9NpJ6r+ag Xnyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="BX5CjAB/"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a17090aad9600b00259a3c7fb52si1780129pjq.27.2023.07.06.08.43.11; Thu, 06 Jul 2023 08:43:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b="BX5CjAB/"; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233129AbjGFOXQ (ORCPT + 99 others); Thu, 6 Jul 2023 10:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233179AbjGFOXB (ORCPT ); Thu, 6 Jul 2023 10:23:01 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021021.outbound.protection.outlook.com [52.101.57.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2085E1BD3; Thu, 6 Jul 2023 07:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwhdvMOTCj1pk6YoWX/0vA8V1MM1yW1X+cgckphBoWw18+TH5Wq4fo6sy5T77KA9dxG2QmsFTIED0utRdGSKbFhjMifbh0Yx5wjIefStAvpwxYREUbfvGnyNJp74WgBoV6/zkzgu1ro93YJgZmAqlvDxcv19Yf0ne/v32iCEfyibMuTwXufpKaiV/jiLLwOxN6tiBgOpj2T1iIVTb3yQ6dQ10HKf/K40XhmE4fLUWzyBE9ipz1Q320hp35gTgZ1ChNcQEwbMJY3ERm6nSf+UmZN+ifGu+PzwaTnIZ9jGa/nCal+N25zkuQTZYRzV9dkKMvcBNMMTgKbW9FMKvxbJdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wG+YaDqOerIORGaH0fUqy7utjqv7UUuWUSk817E/mzg=; b=ndEu3JVKgKXySe5MQlXcBi/fbhKlL2O0ptdcmhzZZxiudcIPTbIuVNkdkB7HkH16H+jm5k6aAN4AnE+XU/Bvf+Gbx1R3+7dta0Lcn6aYfG+gC0CCAU0mfxQfTbhB7RQZI28QC+FK6HoyeJmazK9axvEgoJf1S8XHAN5MIikeRHp7Ubrli0RYpTiUsZolPvoEta0+yaUEHgModwpkI6gDAPusar30t15FZF7HmHAh+AOZc0VXj0LuXz8lKc2c9SPM4H5QN6pffvIkThZvUj7YwHPFN99E7t/QoUkv1YcH+JkRqtxD+dBLRm8stD2aC8qqWCyamxXnaxRzoidhuSwbHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wG+YaDqOerIORGaH0fUqy7utjqv7UUuWUSk817E/mzg=; b=BX5CjAB/nwUpSZIB8jmjak4/kZaXQUY83pGmmBzgho/V+8jgYNNr3ujodWzkus5oPCYtGCbxA/qEh6fTt8pO/YEE2JphEFOWikQdRVCbke2dzDhP87v/7JdeiUCoOKtPp1bBq2vejmj/TjBffepZ2mCOmgtFmAzX+kKEmbktEJc= Received: from BYAPR21MB1688.namprd21.prod.outlook.com (2603:10b6:a02:bf::26) by CY5PR21MB3493.namprd21.prod.outlook.com (2603:10b6:930:e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.19; Thu, 6 Jul 2023 14:22:50 +0000 Received: from BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::733d:6263:4482:ba25]) by BYAPR21MB1688.namprd21.prod.outlook.com ([fe80::733d:6263:4482:ba25%4]) with mapi id 15.20.6588.010; Thu, 6 Jul 2023 14:22:50 +0000 From: "Michael Kelley (LINUX)" To: Greg Kroah-Hartman CC: Petr Tesarik , Stefano Stabellini , Thomas Bogendoerfer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "Rafael J. Wysocki" , Juergen Gross , Oleksandr Tyshchenko , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Andy Shevchenko , Hans de Goede , Jason Gunthorpe , Kees Cook , Saravana Kannan , "moderated list:XEN HYPERVISOR ARM" , "moderated list:ARM PORT" , open list , "open list:MIPS" , "open list:XEN SWIOTLB SUBSYSTEM" , Roberto Sassu , Kefeng Wang , "petr@tesarici.cz" Subject: RE: [PATCH v3 4/7] swiotlb: if swiotlb is full, fall back to a transient memory pool Thread-Topic: [PATCH v3 4/7] swiotlb: if swiotlb is full, fall back to a transient memory pool Thread-Index: AQHZqN4Es6xs27E7q0W1vSuhepPC1q+p0aJAgAKeXgCAAGWX4A== Date: Thu, 6 Jul 2023 14:22:50 +0000 Message-ID: References: <34c2a1ba721a7bc496128aac5e20724e4077f1ab.1687859323.git.petr.tesarik.ext@huawei.com> <2023070626-boxcar-bubbly-471d@gregkh> In-Reply-To: <2023070626-boxcar-bubbly-471d@gregkh> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=a8aa5c53-11c1-447d-8308-ef08c97544cc;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2023-07-06T14:10:48Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR21MB1688:EE_|CY5PR21MB3493:EE_ x-ms-office365-filtering-correlation-id: 2aad2f2f-3f4a-4a93-0f5d-08db7e2c7a80 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ffQ8B6GEk16LjgRECqfLARZg2milg373MaXIenId9pbAhydXyqiowRyCuEtSjHvmWz8CslFOoJOdwPPy6TAHIIyoXSAdLEomrjgAA8N1FiJueN6DY+grG3dT4d+N6jYopUIMOEnqe1Iqrh+pF1ji/035vpeLn9UvQe2il3FQvFwP7gPN7A5GakVYyuAKeMkMs5/jGPvmtFRwCQ5r1vzcGlPjd4nL4JoFRjAhzYUm6AC1W5qE+DpwnOsv8vVD07zz0lYyD2yp/DWTSln2UdCoeQGyrlJWngx8eVQ0Qg89zrySEAGmP4CA1IDithsRcKWmZoe+vWp4i0STxWHIy0pcY9qFwUk+huKeBqdpZN6cj9GcTq+XcAlXwZmy5+s6GFj+TCjF7u3nBTMODt+MreNwwWsO6PE5nAilJxZHxTQnXxzy+G8kge8ZxoCz1zXFP3xOqOcc/ViOW/ooSfdK/78KKppj9nd5yLlYz98XzGumO7NmxPwDxQlWY2HO+8SGpMCTHwHebc7G8V/ksw01ZVdPIbOkFyrdPQY1nR0Mru60esT9d6QTRD9DuGgJw0O2bZimJ89U9rbRuBsYDiREBKpYmQo0cxQAjHT4uKUvU9tqus1Ez/Iji8xty6CyQyatRxYFsWJjrPCn26lFYu0iVXdbUpRUtMWhAYUhalaioeZ131Y= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR21MB1688.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(39860400002)(376002)(396003)(136003)(346002)(451199021)(71200400001)(54906003)(7696005)(122000001)(478600001)(10290500003)(66556008)(38070700005)(83380400001)(33656002)(55016003)(86362001)(2906002)(26005)(6506007)(76116006)(8990500004)(9686003)(186003)(38100700002)(8676002)(82950400001)(66946007)(316002)(64756008)(66476007)(66446008)(8936002)(4326008)(7416002)(82960400001)(41300700001)(52536014)(5660300002)(6916009);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata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kbjFAI0yU511Qm/F7Yj93mmWYQE?= =?us-ascii?Q?4XI2O6pYAwH4LQ61OjlvRqkxVfEFNs8WpiHZ5zfcRhXvnnreaFSqPb2S3TjV?= =?us-ascii?Q?Tuwg1niNEo3cBrOeYFq+SoZ6kX0O1dxJ3GR5xUc+JPEblRPO8HyBHhQyT9Qx?= =?us-ascii?Q?ohCq1i5HAKieEJyip+Kj6aiIFz3XuGleFYeXHS012B2NguRM3G6Wa1hodhNx?= =?us-ascii?Q?keYoBqoK1DpyG6WtL3V9nW8WIhTvvzxvfxWjggIAxxkYWnwo6eW1R+Ukj2a9?= =?us-ascii?Q?yiqMH20LgWjvWyhYSfVlYdWM/V8hcdXEBwGArvi6as0+zEcgs1+XNxZO4wnx?= =?us-ascii?Q?mII7SKLN6oiEX4pKspIfTxYi5Q2PFkW4OVTJR7v4N1muFKMkRvbWMlgZIpn+?= =?us-ascii?Q?X7UN7YkPeAvP2KPaDkph3HqQbcQXiS/LDYjoar/Q99xpKxE7N0Mk0A4WTJ3f?= =?us-ascii?Q?rWycxmCWILHlOMsm6KmzrNEsIXAdR1Upi2vYSMQBwjWG9OYgEC0f/y1Dip+z?= =?us-ascii?Q?averv8YToXbJ7Jf4O9gR5GoYDSiWCtdgwXxoN3qWIS5JEsF8G7FU4fRlwTCC?= =?us-ascii?Q?b8MM8oNO1v/eTC0O+4MUROzlHonkc0uEmtKwrcFL3lsCFC1/kGhakhezEGM4?= =?us-ascii?Q?LUzVWweOmKMFsC+iA9384d7SNCzPhmvjNnjktdQEZ6CrKf8lUverIaxTxSNq?= =?us-ascii?Q?d9S3cFLVzVdOoM2cnKcWI1/pT47njF1ZZEMprTYyGYN/Lp0V3OFObKDZEjaP?= =?us-ascii?Q?pA=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR21MB1688.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2aad2f2f-3f4a-4a93-0f5d-08db7e2c7a80 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jul 2023 14:22:50.1701 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DqFDnJYrC3LQC9s/7hcOB4tP41bB/DlWxzkQUJ0CSsmiPR3HPjjgb5lGqUiN4d+9ahRtC3W7Vc5xrCP1s7UEelf8bvq0Nc35AfvfI/KqtAE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR21MB3493 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman Sent: Thursday, July = 6, 2023 1:07 AM >=20 > On Thu, Jul 06, 2023 at 03:50:55AM +0000, Michael Kelley (LINUX) wrote: > > From: Petr Tesarik Sent: Tuesday, June 27= , 2023 > 2:54 AM > > > > > > Try to allocate a transient memory pool if no suitable slots can be f= ound, > > > except when allocating from a restricted pool. The transient pool is = just > > > enough big for this one bounce buffer. It is inserted into a per-devi= ce > > > list of transient memory pools, and it is freed again when the bounce > > > buffer is unmapped. > > > > > > Transient memory pools are kept in an RCU list. A memory barrier is > > > required after adding a new entry, because any address within a trans= ient > > > buffer must be immediately recognized as belonging to the SWIOTLB, ev= en if > > > it is passed to another CPU. > > > > > > Deletion does not require any synchronization beyond RCU ordering > > > guarantees. After a buffer is unmapped, its physical addresses may no > > > longer be passed to the DMA API, so the memory range of the correspon= ding > > > stale entry in the RCU list never matches. If the memory range gets > > > allocated again, then it happens only after a RCU quiescent state. > > > > > > Since bounce buffers can now be allocated from different pools, add a > > > parameter to swiotlb_alloc_pool() to let the caller know which memory= pool > > > is used. Add swiotlb_find_pool() to find the memory pool correspondin= g to > > > an address. This function is now also used by is_swiotlb_buffer(), be= cause > > > a simple boundary check is no longer sufficient. > > > > > > The logic in swiotlb_alloc_tlb() is taken from __dma_direct_alloc_pag= es(), > > > simplified and enhanced to use coherent memory pools if needed. > > > > > > Note that this is not the most efficient way to provide a bounce buff= er, > > > but when a DMA buffer can't be mapped, something may (and will) actua= lly > > > break. At that point it is better to make an allocation, even if it m= ay be > > > an expensive operation. > > > > I continue to think about swiotlb memory management from the standpoint > > of CoCo VMs that may be quite large with high network and storage loads= . > > These VMs are often running mission-critical workloads that can't toler= ate > > a bounce buffer allocation failure. To prevent such failures, the swio= tlb > > memory size must be overly large, which wastes memory. >=20 > If "mission critical workloads" are in a vm that allowes overcommit and > no control over other vms in that same system, then you have worse > problems, sorry. >=20 > Just don't do that. >=20 No, the cases I'm concerned about don't involve memory overcommit. CoCo VMs must use swiotlb bounce buffers to do DMA I/O. Current swiotlb code in the Linux guest allocates a configurable, but fixed, amount of gues= t memory at boot time for this purpose. But it's hard to know how much swiotlb bounce buffer memory will be needed to handle peak I/O loads. This patch set does dynamic allocation of swiotlb bounce buffer memory, which can help avoid needing to configure an overly large fixed size at boo= t. Michael