Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp49585pxh; Thu, 7 Apr 2022 13:38:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz0LN6XeiUWx7kVyCmtDkeS9l7MUhdLDRQg4WAMojvDPFHzVyfBWUig/U6q1VPp5KU1WMu X-Received: by 2002:a17:90a:5146:b0:1ca:75b8:7765 with SMTP id k6-20020a17090a514600b001ca75b87765mr17799825pjm.86.1649363879975; Thu, 07 Apr 2022 13:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363879; cv=none; d=google.com; s=arc-20160816; b=EU2ELTpMKuPDg3otnXc7YYoFZsohh+MpZuLHURLryZ/VUFZBO3oWFyD0No9bMp635r a1JRlLG8wljHcX4UhG15pElApmQQwk8wcJ24287CFVSYMVZsGqAPgA3xUWCvB592u+l5 x8DRZ8dv6PM1KgCphnbkp5dMYUBiSyNiLQj8PIDbw/1lk3ac84x6ITp/Gy3Kx2Oe/Ubr 4eZXmn2egXwWF8GmjZCt0LmktTRx0O2lALgnmjINrDE+MjVVhtb8gyEHXYE2XMYRKN+0 +oTmNAyC5fVWyMCSqbnhk+LChOyGpsoZEdqWMBddbILQmBeyaWGXEjmIzy6EfKQ8W7Gm 4uhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=K1hkIaTJl+2k4Y8GqaoI1Kpt31tTLuUWcY+NhRoTAwI=; b=XzTkH+c7h36CApiBKYCPu4xweSLJ+k5EhB4Ji5tGHMNvxBhwU4n6oSUpog29F2wY+H rqgswgEgPOFw2sX3bwI12gdr06F9OxzsarLoktsvKgHRgU2VkJoiuQ2QI1FIQdPmXeSv LfKRigciKng6Rs4XEcWVBAvnD1Iok4yciEhYpalwBo3YKdM3mYQx39qnfVkwpjylEvp2 vhDzr1U2fPJmrOAaYn2a0nYKuzPTySB5FpIDkZ/pWlizN8nMRPJqCaR/3GM0hiw+E+XA GE6Dj8rYxkewfJ50YUbTBih+uskK7EJntQLmolrUWw8rZsdaiMTW9FpVzkESex4ftFUh fIXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r76-20020a632b4f000000b0039cb4085773si4825396pgr.876.2022.04.07.13.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:37:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25B113A48A6; Thu, 7 Apr 2022 12:48:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238131AbiDGNd7 (ORCPT + 99 others); Thu, 7 Apr 2022 09:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238922AbiDGNdy (ORCPT ); Thu, 7 Apr 2022 09:33:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6213C286DC for ; Thu, 7 Apr 2022 06:31:52 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E1C9A12FC; Thu, 7 Apr 2022 06:31:51 -0700 (PDT) Received: from [10.57.41.19] (unknown [10.57.41.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 23C3D3F73B; Thu, 7 Apr 2022 06:31:50 -0700 (PDT) Message-ID: Date: Thu, 7 Apr 2022 14:31:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v2 1/2] iommu/amd: Enable swiotlb in all cases Content-Language: en-GB To: Mario Limonciello , Joerg Roedel , Will Deacon Cc: Christoph Hellwig , Marek Szyprowski , "open list:IOMMU DRIVERS" , Suthikulpanit Suravee , Hegde Vasant , open list References: <20220404204723.9767-1-mario.limonciello@amd.com> <20220404204723.9767-2-mario.limonciello@amd.com> From: Robin Murphy In-Reply-To: <20220404204723.9767-2-mario.limonciello@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 2022-04-04 21:47, Mario Limonciello wrote: > Previously the AMD IOMMU would only enable SWIOTLB in certain > circumstances: > * IOMMU in passthrough mode > * SME enabled > > This logic however doesn't work when an untrusted device is plugged in > that doesn't do page aligned DMA transactions. The expectation is > that a bounce buffer is used for those transactions. > > This fails like this: > > swiotlb buffer is full (sz: 4096 bytes), total 0 (slots), used 0 (slots) > > That happens because the bounce buffers have been allocated, followed by > freed during startup but the bounce buffering code expects that all IOMMUs > have left it enabled. > > Remove the criteria to set up bounce buffers on AMD systems to ensure > they're always available for supporting untrusted devices. FWIW it's also broken for another niche case where iommu_default_passthrough() == false at init, but the user later changes a 32-bit device's default domain type to passthrough via sysfs, such that it starts needing regular dma-direct bouncing. Reviewed-by: Robin Murphy > Fixes: 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") > Suggested-by: Christoph Hellwig > Signed-off-by: Mario Limonciello > --- > v1->v2: > * Enable swiotlb for AMD instead of ignoring it for inactive > > drivers/iommu/amd/iommu.c | 7 ------- > 1 file changed, 7 deletions(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index a1ada7bff44e..079694f894b8 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -1838,17 +1838,10 @@ void amd_iommu_domain_update(struct protection_domain *domain) > amd_iommu_domain_flush_complete(domain); > } > > -static void __init amd_iommu_init_dma_ops(void) > -{ > - swiotlb = (iommu_default_passthrough() || sme_me_mask) ? 1 : 0; > -} > - > int __init amd_iommu_init_api(void) > { > int err; > > - amd_iommu_init_dma_ops(); > - > err = bus_set_iommu(&pci_bus_type, &amd_iommu_ops); > if (err) > return err;