From patchwork Fri Apr 12 14:21:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13627830 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 A738386ACC for ; Fri, 12 Apr 2024 14:21:55 +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=1712931717; cv=none; b=gAV4yh/bCoFxOjzFy7FU3HNpxSzXNeavUegdRivkGwLTPC56gJRRQ/bWJMreU39bm5OEXSgmNgFhKgGeNEpW2pkE6hHuFEvVXXggQSgmY15drpcNVb3ZQIVGyzSiM4Xo9zdt/CD3ph3sq2tAy5jNldfXKb9PQG1f3cx/9dLcCT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931717; c=relaxed/simple; bh=pVzRhZ6ZT+x69i7trRwSyvoC5xLpBia3FSDH6V6AM6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mDjqN63y0LDZSNWgAik7R/Cu3gXVkF3Bb8bT5NswG4nD9FUGhp7tEwcxOfGAZM4E5HtlX6fkUEofQncHCaCndhTjblginDzf7RP8o+bGO44ezbPAE6Pw+oVUkp+kdPWa93Y63gIngCZeDUO3KZWitJQnZr+xeZhfbm6xMqljMVY= 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=RXOBjfRU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RXOBjfRU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712931714; 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=RXOBjfRUcwChQMCj6teGydvSM2z24/4jtpuV11ehuZoz2i/Ab7xAodif3RuCAHfgEZy5LP RscsSX8bVhopCVGw9AMARePeTmyzngz/x9dq8KAem6O6MqndEhrGaLeFjsa0yfhyg3TcDP XjmIxIwLTNMOXiGCeZcRdHHSrOxl3lU= 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: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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