From patchwork Thu Apr 4 16:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13618057 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D802CD1299 for ; Thu, 4 Apr 2024 16:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE216B0099; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8D1F6B009B; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2DB86B009C; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 81D9D6B0099 for ; Thu, 4 Apr 2024 12:37:20 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 309C7C057C for ; Thu, 4 Apr 2024 16:37:20 +0000 (UTC) X-FDA: 81972404640.18.B614984 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 84EAA160008 for ; Thu, 4 Apr 2024 16:37:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712248638; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zaZWU0YkYnbWySa48R8KGwWh1EeftVOr0gzeEuzgbNQ=; b=gEOMZZbQ8Ws8cvSA8BAOfoPsJdgVRud4nXe2orKPsxUDt9aX0L1WbTI/Cb3CkhVMHp3270 j4aSGWNEILoajNUq9GW+/XvUlJvRIrTEOePgYl6QaM4RtBKbuGWIq3SyPGTWtXh87aLF9k 5h3Px3eahGs+TYjWOLIC4txdm37in/k= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712248638; a=rsa-sha256; cv=none; b=CNiFGX/L8NHc6+gwzguYMNQLpZVEuMnJIzfCnpCOdXcDXb596rGWwEtFf+9GoFW64Yfefy qr3oLCL+hgyuexPn9uV7bm1xzDkfrVS4UHRkedOCQlWRMuLd2Iqk3PlxEzn5Od4QHHCFVf HZFEoHrJc1YDmfOttAIOj2tUjElxc84= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712248637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zaZWU0YkYnbWySa48R8KGwWh1EeftVOr0gzeEuzgbNQ=; b=Zy9nG69GyflDis2XEVjZIVmhdv5f1LJtNOSkJAT1gjkU5jrIFwM2uxe1poXRHlSafvu4aA ATEugUWNr41OA8aqd5r5P654XIfsibXxpv3NqWmWpYU+XIBK+NtcFpaLIxZemqcG9DWllL IiYmdiTE8OAEJg9tZeAtSMpEl1RACzc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-telD-LxGMoCt6ciulojX3A-1; Thu, 04 Apr 2024 12:37:14 -0400 X-MC-Unique: telD-LxGMoCt6ciulojX3A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41945282479F; Thu, 4 Apr 2024 16:37:13 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8064E3C24; Thu, 4 Apr 2024 16:37:08 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Thomas Huth Subject: [PATCH v1 1/5] s390/uv: don't call wait_on_page_writeback() without a reference Date: Thu, 4 Apr 2024 18:36:38 +0200 Message-ID: <20240404163642.1125529-2-david@redhat.com> In-Reply-To: <20240404163642.1125529-1-david@redhat.com> References: <20240404163642.1125529-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 84EAA160008 X-Stat-Signature: 8rguhkponji3q14rcn5picp7q8yu4ag1 X-HE-Tag: 1712248638-692513 X-HE-Meta: U2FsdGVkX195bbSE0I15yY6L9D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FpuzowKNoIst/10GtUmADcZDbBSVqUAdxB0HTdbo1EnsVZX9bZRrrnYVo8xsDDRmw5wQuvMJMOfqbLYnSm7X+D1bfF1v14XipGbxhz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: wait_on_page_writeback() requires that no spinlocks are held and that a page reference is held, as documented for folio_wait_writeback(). After we dropped the PTL, the page could get freed concurrently. So grab a temporary reference. Fixes: 214d9bbcd3a6 ("s390/mm: provide memory management functions for protected KVM guests") Signed-off-by: David Hildenbrand Reviewed-by: Claudio Imbrenda --- arch/s390/kernel/uv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c index fc07bc39e698..7401838b960b 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -314,6 +314,13 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) rc = make_page_secure(page, uvcb); unlock_page(page); } + + /* + * Once we drop the PTL, the page may get unmapped and + * freed immediately. We need a temporary reference. + */ + if (rc == -EAGAIN) + get_page(page); } pte_unmap_unlock(ptep, ptelock); out: @@ -325,6 +332,7 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) * completion, this is just a useless check, but it is safe. */ wait_on_page_writeback(page); + put_page(page); } else if (rc == -EBUSY) { /* * If we have tried a local drain and the page refcount