From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BE0F19DFA4; Thu, 15 Aug 2024 14:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723732110; cv=none; b=MLeiFGU1lKUieAhrTrsY176dYWfD7J+id61nsI2DhklI/rUQOA/YdP527k6cApOk9yJb3FR1kgszqiTZHKKnrW+gIFv8W3XStupFZDIABfw55WDeEINMJGpgxwmHrhUHgXJmhES+VeE7XFDwGIVtloJ9y/cO42MgRrhxkwZdp4c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723732110; c=relaxed/simple; bh=NFhZmzEG6KhDXWzeR/4KyloH/jrUEOmlgPUYlpuoPAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BEp4Jbf8hGCVYoghaZCpAhZ5AYk4mqk3Ezk4WUn636h7G339uUBb3dM3QPtd7iqhNFRUCUv39zm+oNgu0miB9A+e88G/uhHYUprV4xbSBELAq1S2rWxl1pRdzoSZyqzI14w2yrjJDr8r3ZgekSxCTaXx8a6uYrrxIsLr/n+PIAs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HjWW19uU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HjWW19uU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C718DC32786; Thu, 15 Aug 2024 14:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723732110; bh=NFhZmzEG6KhDXWzeR/4KyloH/jrUEOmlgPUYlpuoPAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjWW19uUaXQVwXp1McgaH9q6r+nY9vGAEOFQH1MJrsJg+4sxlYv48ZrN5tHFgogd0 FQ6xCd/48K6vbTDdJUHjfiyyc2o5YKTK1xNyeiGyD9xW39Q7UOquOOTePrfe3eQN6x pQC9EfFAlWDVgIdLawFqIm/0IiGEGhBTIz9he4NI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Alexander Gordeev , Sasha Levin Subject: [PATCH 5.10 076/352] s390/uv: Dont call folio_wait_writeback() without a folio reference Date: Thu, 15 Aug 2024 15:22:22 +0200 Message-ID: <20240815131922.180958015@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131919.196120297@linuxfoundation.org> References: <20240815131919.196120297@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand [ Upstream commit 3f29f6537f54d74e64bac0a390fb2e26da25800d ] folio_wait_writeback() requires that no spinlocks are held and that a folio reference is held, as documented. After we dropped the PTL, the folio could get freed concurrently. So grab a temporary reference. Fixes: 214d9bbcd3a6 ("s390/mm: provide memory management functions for protected KVM guests") Reviewed-by: Claudio Imbrenda Signed-off-by: David Hildenbrand Link: https://lore.kernel.org/r/20240508182955.358628-2-david@redhat.com Signed-off-by: Heiko Carstens Signed-off-by: Alexander Gordeev Signed-off-by: Sasha Levin --- 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 8c73d4901e145..03a8a9a52186a 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -320,6 +320,13 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) rc = make_folio_secure(folio, uvcb); folio_unlock(folio); } + + /* + * Once we drop the PTL, the folio may get unmapped and + * freed immediately. We need a temporary reference. + */ + if (rc == -EAGAIN) + folio_get(folio); } unlock: pte_unmap_unlock(ptep, ptelock); @@ -332,6 +339,7 @@ int gmap_make_secure(struct gmap *gmap, unsigned long gaddr, void *uvcb) * completion, this is just a useless check, but it is safe. */ folio_wait_writeback(folio); + folio_put(folio); } else if (rc == -EBUSY) { /* * If we have tried a local drain and the folio refcount -- 2.43.0