Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp167801lqp; Thu, 4 Apr 2024 09:38:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyCkKWqXBXC9k9dSPQShtnFKvqEksV6jLbIMHrjm0QlWkEM1zzwuyp8pn1H2kAoIdws8FnVcFxnbfQKrntO9BJ57oGmD+6M9g8zfa/ew== X-Google-Smtp-Source: AGHT+IGLGGNWKwcpDqvuZl/eHXAT8RLk2Nr+opJq7JAn/tw4FtKBa7kz8yls1j9SF7atK98VkOLW X-Received: by 2002:a50:9998:0:b0:568:abe3:52b2 with SMTP id m24-20020a509998000000b00568abe352b2mr2534840edb.23.1712248695629; Thu, 04 Apr 2024 09:38:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712248695; cv=pass; d=google.com; s=arc-20160816; b=Uq2C3IXszYC5++RLGx6YRS4VF4vXshQHkUZdIqjhXqYCyJlwfVdm7JuSexW/TMjmZz WbEOYjZiM+4NCUATuBVVCn/aicgdj2gLHXZomxZsA6ibtHCPC2CgmWP4HpPWl31WNu2W aGSGARYKRSihFZkrndIXZ1K59A4emZbZZpoVp23nSNli9gFHbtxmwEc25N3ePD83ognj IyFhCxgVD1J5C1+an5ZlIeSiEoR3cIy5rRY/wFiegnuGXaiaIacfAYQz47NFe1Jw3hF2 /W8GIj9ENx6otZt7NgON/qrEjmkktGRgen19tmNf6q4MjTDGSN4IEisSQDLxy7126sF5 WD9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zaZWU0YkYnbWySa48R8KGwWh1EeftVOr0gzeEuzgbNQ=; fh=t+LjNwjqFDXyApTP0a0u3Yye20bYk5Mfk6wncAYiAak=; b=kCRk33bzSG8pI/33MJujpXJ/G9BoinFcafX4Li/Gcy0F2uuqrYFGRLspuMuAqpUuzN JCVwPdN8oZAg0OR3ZlZGRmM4nFjEOBFaXj0eot3iohA21Qj3d/Jglss9UdVvOrQoHIFg Q3qQdk3FWNUfZwWrvcjC4MCG65oRp0UKBkx9Oxw01p8vY2xYLjctYNv+DliF52/wPPHc 7H/aEB/4rAWVz+BJTooEXI50N+Q/fFMiIfJEbUq8LkfTdrIulKcz3eaWsqwRtyhG0Ybw 3Q+MwJYGF1CkVO1nwYsnOX1t2ombnRp67gHvzBNl6zldKg0T8679GoebqMAbkI7QxImF 1Ixw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-131831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131831-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 26-20020a508e5a000000b0056df3a31bc5si2708453edx.639.2024.04.04.09.38.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 09:38:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zy9nG69G; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-131831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131831-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 68D651F224B8 for ; Thu, 4 Apr 2024 16:38:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EE5D12D765; Thu, 4 Apr 2024 16:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Zy9nG69G" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 D8E2B12D1EB for ; Thu, 4 Apr 2024 16:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712248640; cv=none; b=DmsT8uhaaskka0z64tLPDktU9h2i8Cf16wOwE0EuWBv5AYyZcHLB4thW8CdK7HWPObxTew0/ltZbqu8sp78V2nEXvXtCaQPnZemHFITiS6f3Zt/vZk0dFW8C3IbNcLYDV0W0QSgAXSPOXjKFhd42dOTgD1+FjkDyNtx0mRlcIFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712248640; c=relaxed/simple; bh=czE5N/0J5tmfJlu8WYjn9+LYDN7w0lpHFxch4r4j6P4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPen9kNvCEzn9RhxdByO7hb5/ZhS0JN8LfubmiJi89hWhQnEtyiSyDXsxknZtfU9gshQTJBRckj5vicvauBL8gwr657UM44FkkKFmU7sTqfOGjWP1R6RqhJLXFRbAEKdVKPzen92M3i562lK3NJAmGBKSyldtPPU0Mq7cF5D9MU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Zy9nG69G; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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 --- 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 -- 2.44.0