Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12511495rwl; Tue, 3 Jan 2023 15:58:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvOpYi5b9P/S/auEocIv4hnehb8ixuLwaj92PXjsT1wt2bzX2PQpSS8h0HW/epjWqYGdpZ+ X-Received: by 2002:a17:907:6f09:b0:7c0:a877:1cf1 with SMTP id sy9-20020a1709076f0900b007c0a8771cf1mr43795479ejc.12.1672790297342; Tue, 03 Jan 2023 15:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672790297; cv=none; d=google.com; s=arc-20160816; b=ImqM7IhMY91tpC9W5PFbxzBQD95cxPGmeifAoEwfg+2tfSsj+xKrVyYNZZLMGtpPMY ic1JLuYbKWtfFlUsQ5zwpRnY1sn0mgYkBpHyfGEov1tXn5sFVt5D1kY0HgOw4FrjEdLU PxdsTIB8IfgCvAoSQmehLAIsNOLBcQYO+qCTHnXO0KeebG2OxctbJdlzwW64Ii60fJZE +I84TDUwYc7ThgbYhwq78EFKVt7KMjki5I6XDsO4c2RSg7q3fWsFhApCAxLyYgIoSFgf Y2rIhkuq9eaKisZV9i8lJSubqcQ9LhgxCbtUsVBm8HXyqsCb06Q5KPHOsSWMfqIGw/cq L8Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4IcK9nCCJcWx4DXnUq9jN3aJ923JmnvuRI8XJBFIY/0=; b=E+H0yrC/ImrviI71l5ZSyhKVwo2JPoGWvhyDpqhqlgQn1yq2/1mDqc5riyQmtoABgk sLXPcdRS2Ol0tFGdWnDf/WiY7VoNBSkE72SGR2TN8mHQxi3aTTsiv46HUthNRjAboC5v FUvKP/2w7pubCiVEmu6PztVqj2bmPkTZC3th6VdVMnyCoRluT0hSIUaJJqdxtsngGPQE km7e+UeqFtF5AU55XU4YYU9HwB880WYiaWarKI7PV3N/+wkrwfje33IUHsSLTJgsYumL 1xW9hQ3Ta2UD88DN7H0ncGt7CpZaEEXSoLrugC66RQmAVGLSiBxMsughyaUdqRkBUCnE U9XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=AinaOJu6; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf3-20020a17090731c300b007c090dba7bcsi30496219ejb.210.2023.01.03.15.58.01; Tue, 03 Jan 2023 15:58:17 -0800 (PST) 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=@ziepe.ca header.s=google header.b=AinaOJu6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237008AbjACXjH (ORCPT + 59 others); Tue, 3 Jan 2023 18:39:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234209AbjACXjF (ORCPT ); Tue, 3 Jan 2023 18:39:05 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78E94F9 for ; Tue, 3 Jan 2023 15:39:04 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id s9so25870716qtx.6 for ; Tue, 03 Jan 2023 15:39:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4IcK9nCCJcWx4DXnUq9jN3aJ923JmnvuRI8XJBFIY/0=; b=AinaOJu6/IFu11c89krxqHstp+Qx6bg/GaS+/T4HG1pBBDurgbVIkkpQhX5l5tMvqb Dt1aixulGN49hn0TCZDfJL7P2ujEI3Sb32Da2Ad7RzLbA8dzxkEYLQq3GZQcrenecSyI FUTCfOup8/4qyfgTpAhOtrWipWNbIm0VnCSVdwFYngsL8nHD9rkzKFRezi0Kl7Q3hvbA wfliVsDb7QqWxrnaKcP0ps9OCvq8tpOVmKmO7wCblz0d6e8uNpGAskXpNHAZ3s+sAcAQ h+10YPQxw7ir5wvpzI0aHOfOWM7euZeizl49b4id9HdeFXirSJK4GNlbhtO17TXeoseg BCdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4IcK9nCCJcWx4DXnUq9jN3aJ923JmnvuRI8XJBFIY/0=; b=n4LHSZT2GCiskrH5/tABl1mQs48j4fRMB5dKaOhxntLY8PQpLOWO/C16OjBCx8q3ni I/mt91WBdlAqUhlHsatSK2DdbBhv4mPHOCo7gE09jsTbWS0ocDgtPjFlV1j8lTlaAmGD vSCOdX07Bi4V1BhJ7+rFK97IWGbD67T2U5TIIoJi53e0hu0oHSMZyaxMSkfC0kemUOHz R9I9uTIC1WVr1e3PqORCqv0ZPna3g1p+bGVyycX/N5DSxcnxteYhtIx1x3CrXmdUm75a 2QJoMwKkDm9uCLz64DgSTJWnoWr3ehIFRnjUb7iWHuB6OuezvvshajtYGlNNprFz+0rD pFgg== X-Gm-Message-State: AFqh2kpMVNl+pwz5qZnqXnKHo7STLeoELVuE7Uzbw8ZNAWDmU0SViI1U Ka8oSqhxc8lmiV2Fo3e8FcgYEw== X-Received: by 2002:ac8:73c7:0:b0:3a7:f3e7:5149 with SMTP id v7-20020ac873c7000000b003a7f3e75149mr59471515qtp.61.1672789143621; Tue, 03 Jan 2023 15:39:03 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-50-193.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.50.193]) by smtp.gmail.com with ESMTPSA id m10-20020a05620a220a00b006eeca296c00sm22545055qkh.104.2023.01.03.15.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 15:39:03 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1pCqs2-001cNC-IA; Tue, 03 Jan 2023 19:39:02 -0400 Date: Tue, 3 Jan 2023 19:39:02 -0400 From: Jason Gunthorpe To: Niklas Schnelle Cc: Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Pierre Morel , Christian =?utf-8?Q?Borntr=C3=A4ger?= Subject: Re: [PATCH 1/1] vfio/type1: Respect IOMMU reserved regions in vfio_test_domain_fgsp() Message-ID: References: <20230102093452.761185-1-schnelle@linux.ibm.com> <20230102093452.761185-2-schnelle@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230102093452.761185-2-schnelle@linux.ibm.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Mon, Jan 02, 2023 at 10:34:52AM +0100, Niklas Schnelle wrote: > Since commit cbf7827bc5dc ("iommu/s390: Fix potential s390_domain > aperture shrinking") the s390 IOMMU driver uses a reserved region > instead of an artificially shrunk aperture to restrict IOMMU use based > on the system provided DMA ranges of devices. In particular on current > machines this prevents use of DMA addresses below 2^32 for all devices. > While usually just IOMMU mapping below these addresses is > harmless. However our virtual ISM PCI device looks at new mappings on > IOTLB flush and immediately goes into the error state if such a mapping > violates its allowed DMA ranges. This then breaks pass-through of the > ISM device to a KVM guest. > > Analysing this we found that vfio_test_domain_fgsp() maps 2 pages at DMA > address 0 irrespective of the IOMMUs reserved regions. Even if usually > harmless this seems wrong in the general case so instead go through the > freshly updated IOVA list and try to find a range that isn't reserved > and fits 2 pages and use that for testing for fine grained super pages. Why does it matter? The s390 driver will not set fgsp=true, so if it fails because map fails or does a proper detection it shouldn't make a difference. IOW how does this actualy manifest into a failure? > - if (!ret) { > - size_t unmapped = iommu_unmap(domain->domain, 0, PAGE_SIZE); > + list_for_each_entry(region, regions, list) { > + if (region->end - region->start < PAGE_SIZE * 2) > + continue; > > - if (unmapped == PAGE_SIZE) > - iommu_unmap(domain->domain, PAGE_SIZE, PAGE_SIZE); > - else > - domain->fgsp = true; > + ret = iommu_map(domain->domain, region->start, page_to_phys(pages), PAGE_SIZE * 2, > + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); The region also needs to have 'region->start % (PAGE_SIZE*2) == 0' for the test to work Jason