Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp180914lql; Fri, 12 Apr 2024 07:22:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW0uPYOQMaN9NJDy/WrWEDGFBoT9mDVvRi6t5qxmIIO1CUYrHi6Nnzhh740pAUFQ5sknX7pTxIopQr/LPZeeBTB3atZdC7g9PiPOTHICg== X-Google-Smtp-Source: AGHT+IFhlyv1zDE4HHYzToH/nexyYSobwNUfGFNqcJemMCdlq4orCeZWnIc0Vgj47i4L3WSDSCT9 X-Received: by 2002:a05:6512:e85:b0:513:d246:6e65 with SMTP id bi5-20020a0565120e8500b00513d2466e65mr2085273lfb.50.1712931742938; Fri, 12 Apr 2024 07:22:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712931742; cv=pass; d=google.com; s=arc-20160816; b=l5fFbs1Ix++npnw5B9tL3T0aVbwVvwKRG8iBqw5oFG3IMLJ1k5U4BUqXV68kK1FRfg yCWOepIfM6t5NUjEszSEemajzIFsITrgbWKdvCgmdzRP6lITdtfWuuALVrA+zxpqeODh FioTI8qXQot9gp/4KDdKPQVZvxOaSNYO4MHiWYSunXYBgFtQJS0PCB1eAr6xVkFlp2ME FOggvUwx0GbLlhlLNc+6U14NTuHIu8aETlfSS1+4hTChl9fEJNL2tN1UwFG3pWNEOeRl qNElNUfECXTgCVYMyg29QxQCCdk7r455Wj51xxQhYPofyU0gVoTk696pR7o30dRlcVge l22Q== 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=mANI+UcvWmCI6nEby2g18+Ah/SQ4byG86Q1u6vzzE1Y=; fh=A+QcyawwK6Yq8daxuWFm+g/417ivXyGCFoP00qnMPro=; b=kio8hBFNBNOKHuJuPquzKxus5/GKfcyTAzxW7WutjtqAAklRk9pzhdbmYQmb3fiTqF YwjJS8KEfVPOzlMp+i0nrOPW1i1nfQKyfGa/oHjDPNwTxqM+224OCJDOaIIpvc6VZe2w v5UuhktJX4ZxD2/t+LcKfhYGsSrdz5qafQoN9MzishY87m46pIWxzHytx/v6zGooec/O M1ng2NVD6zedhNOlRI1UtIdMoBaeqxAbxd0Xw1uzEl0y2nMdlTej40ZzgjMkfL+9pHHk im0QajDCdk2x/4R5YHfb8JtIAhcNj6EMDni3OtlH5kc7mqP+t9PCtlrYXJ+/5uuX4TmN 2nfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G1t+Dzay; 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-142815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142815-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ky24-20020a170907779800b00a522e8dec86si946857ejc.583.2024.04.12.07.22.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G1t+Dzay; 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-142815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142815-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 794281F2141D for ; Fri, 12 Apr 2024 14:22:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33D5B127E21; Fri, 12 Apr 2024 14:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G1t+Dzay" 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 03E4855E4A for ; Fri, 12 Apr 2024 14:21:51 +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=1712931713; cv=none; b=MCsdmMW/v/wj+Q00QHZ/2AxKZ96TKGCAxQfv1n2rI8hegY0MILBnRp8PQmRDFOqy3mEHGRE4zTi4BzlvF0oeYCvcMoEuY5HEUcvb/y3lJ0tuG/OOrQhC6hfSICRE7t1jbwLQanMj6hR44gm0n+wFX9MzXQb2vTQrrkm6JbLOF04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931713; c=relaxed/simple; bh=pVzRhZ6ZT+x69i7trRwSyvoC5xLpBia3FSDH6V6AM6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u9v95TX+t+88RHkvW10TEnaGy62IXOQYxbP/adTBip3M0Nz+qe5h2lePT/PFMu5pjdqJ+yPhdp/IpXg8NTDmlSti5hGAes4no5HueUY4Jwyxf94QQGBsGiJ5M+fOSeTiIVE6/k1d93xeQTDOoDk8Hc3oYjNYe8Y7PoT/DoiVyhA= 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=G1t+Dzay; 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=1712931710; 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=mANI+UcvWmCI6nEby2g18+Ah/SQ4byG86Q1u6vzzE1Y=; b=G1t+DzayZfVh1XjbU8kHbP/oZW9czgaFpiZbwODRWQFfPFKjAwWrA7lPLC9k3PBgMkOFdi /dThcUQqpTJFu19o/vutnUe3hI0m3VQo/Rpp9y6vrFJGFQLmHzpGx72SdW3Ilj7UWZUhl9 MqqCYTqu4tzw8jkTWlxfdlD/Np5ezlE= 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-65-y6V8ahENNPaWSwcNT8uCxw-1; Fri, 12 Apr 2024 10:21:49 -0400 X-MC-Unique: y6V8ahENNPaWSwcNT8uCxw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 75EBF3C025C8; Fri, 12 Apr 2024 14:21:48 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B6C740C123D; Fri, 12 Apr 2024 14:21:45 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Janosch Frank , Claudio Imbrenda , Gerald Schaefer , Matthew Wilcox , Thomas Huth Subject: [PATCH v2 01/10] s390/uv: don't call folio_wait_writeback() without a folio reference Date: Fri, 12 Apr 2024 16:21:11 +0200 Message-ID: <20240412142120.220087-2-david@redhat.com> In-Reply-To: <20240412142120.220087-1-david@redhat.com> References: <20240412142120.220087-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.2 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 --- 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 265fea37e030..016993e9eb72 100644 --- a/arch/s390/kernel/uv.c +++ b/arch/s390/kernel/uv.c @@ -318,6 +318,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); @@ -330,6 +337,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.44.0