Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1741683ybg; Sat, 19 Oct 2019 01:30:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT6UCtjVPYhvR/rca+UFN4lBO6K0AQRSgoiHFCSiFP8uzAAHN73VLTTpjKVPE2rxq0E1Df X-Received: by 2002:aa7:df0d:: with SMTP id c13mr13747682edy.61.1571473857751; Sat, 19 Oct 2019 01:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571473857; cv=none; d=google.com; s=arc-20160816; b=uaKNtDndigJelK9IRrqzs83rvVx/RXOk0hk3/dUJA8+19XSRyS4FQCx1IpSMXhS5Sk pB/1NvdNK6g2/EB/TmJg1h92+EyZ9GBwsrRAcm5DwGJMKsFr1Y6Lcu3pG3R1LKAxEHs+ Vowm8w0tvV04A/L09A24/iO452uVFToUYlljt+hIbxG9r/LoS84Zu7jkptO4P9t0qAsZ vvEMLnZ9TrBtmU6qTsdMzs9JX5quh5fLkviLw/Hd2sJUmePLgUKyjTurDVS/nmksayc4 FLKOLGYSUEkgTMk7Qf53NLupAKwTCZ1TNDENRE/AZwbw4JRIAO49ldJ7KzeGTByzgsXJ 7Ysw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=s271gI3eoeqIOWxdouKL98byT5KCcincuWRH0/Zt2Wc=; b=cXrWmIEKXPIY21xJzWU7wUdXSJRE9LY4m6uSy0UMb0P07r8onUwI7+ZLvepGyncLF4 2mN7c34QapqUyHbQ1Bnp5At/Kicw3gr+gWgM2etioTiLhowdPRdaqZpD6RZzUu57xmeo +NA5dv0e+avWD3xs6Qx00XPDDYAzKS5ycH8vUMsBbvotlODVqvq33ZuM6c9Kd1IwTnZN 3nCvJXkMG+bx5btPYlUs0E2cwzpPLz3wJaJpv9uIgN2ggmwbIq5SsEn/7i059ZXuYR5r 2qU7vd1NN11ciulT59y3AS5yz2qMbbApNXeEl/2nxOOJFhpIa7X1EjuYSYAkswiyb6UC o9HQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si5425557edc.404.2019.10.19.01.30.34; Sat, 19 Oct 2019 01:30:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2634231AbfJRO4F convert rfc822-to-8bit (ORCPT + 99 others); Fri, 18 Oct 2019 10:56:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33136 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727242AbfJRO4F (ORCPT ); Fri, 18 Oct 2019 10:56:05 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81E618A1C8F; Fri, 18 Oct 2019 14:56:04 +0000 (UTC) Received: from x1.home (ovpn-118-102.phx2.redhat.com [10.3.118.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2961860600; Fri, 18 Oct 2019 14:56:04 +0000 (UTC) Date: Fri, 18 Oct 2019 08:56:02 -0600 From: Alex Williamson To: Ben Luo Cc: aarcange@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfio/type1: remove hugepage checks in is_invalid_reserved_pfn() Message-ID: <20191018085602.17f2edbb@x1.home> In-Reply-To: References: <1d6b7e1c40783f2db4c6cb15bf679a94222ec6a3.1570073993.git.luoben@linux.alibaba.com> <20191003164133.GG13922@redhat.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Fri, 18 Oct 2019 14:56:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 Oct 2019 14:42:32 +0800 Ben Luo wrote: > A friendly reminder :) > Thanks Ben! I've added this to the vfio next branch for v5.5 with Andrea's R-b. Thanks, Alex > 在 2019/10/4 上午12:41, Andrea Arcangeli 写道: > > On Thu, Oct 03, 2019 at 11:49:42AM +0800, Ben Luo wrote: > >> Currently, no hugepage split code can transfer the reserved bit > >> from head to tail during the split, so checking the head can't make > >> a difference in a racing condition with hugepage spliting. > >> > >> The buddy wouldn't allow a driver to allocate an hugepage if any > >> subpage is reserved in the e820 map at boot, if any driver sets the > >> reserved bit of head page before mapping the hugepage in userland, > >> it needs to set the reserved bit in all subpages to be safe. > >> > >> Signed-off-by: Ben Luo > > Reviewed-by: Andrea Arcangeli > > > > > >> --- > >> drivers/vfio/vfio_iommu_type1.c | 26 ++++---------------------- > >> 1 file changed, 4 insertions(+), 22 deletions(-) > >> > >> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > >> index 054391f..e2019ba 100644 > >> --- a/drivers/vfio/vfio_iommu_type1.c > >> +++ b/drivers/vfio/vfio_iommu_type1.c > >> @@ -287,31 +287,13 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) > >> * Some mappings aren't backed by a struct page, for example an mmap'd > >> * MMIO range for our own or another device. These use a different > >> * pfn conversion and shouldn't be tracked as locked pages. > >> + * For compound pages, any driver that sets the reserved bit in head > >> + * page needs to set the reserved bit in all subpages to be safe. > >> */ > >> static bool is_invalid_reserved_pfn(unsigned long pfn) > >> { > >> - if (pfn_valid(pfn)) { > >> - bool reserved; > >> - struct page *tail = pfn_to_page(pfn); > >> - struct page *head = compound_head(tail); > >> - reserved = !!(PageReserved(head)); > >> - if (head != tail) { > >> - /* > >> - * "head" is not a dangling pointer > >> - * (compound_head takes care of that) > >> - * but the hugepage may have been split > >> - * from under us (and we may not hold a > >> - * reference count on the head page so it can > >> - * be reused before we run PageReferenced), so > >> - * we've to check PageTail before returning > >> - * what we just read. > >> - */ > >> - smp_rmb(); > >> - if (PageTail(tail)) > >> - return reserved; > >> - } > >> - return PageReserved(tail); > >> - } > >> + if (pfn_valid(pfn)) > >> + return PageReserved(pfn_to_page(pfn)); > >> > >> return true; > >> } > >> -- > >> 1.8.3.1 > >>