Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp686512lqo; Wed, 8 May 2024 11:30:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFecuBMXNSCkjIcGcXlVMEl/OdtfTJoK/U/w+SHH/9LLNFDuw4uXa++SzHfiivOCC1Omrg+j3UfoHMokU6lkvq1wAtsH6kYPKBFGh4zw== X-Google-Smtp-Source: AGHT+IGvIK8TGI7uc2dGK55elTWoMjhBPOvArX9I+FRsH6cAThKNpfdSx30L9VewOziZMfP+rYf2 X-Received: by 2002:a17:903:2291:b0:1eb:73c2:6b4a with SMTP id d9443c01a7336-1eeb03a6997mr43568735ad.8.1715193037280; Wed, 08 May 2024 11:30:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715193037; cv=pass; d=google.com; s=arc-20160816; b=eHf+PHNwGnfv03MjE1ylQWgBy0N525IGn//4TKNF5adM8ae4gJBnH7Zu4mx9ehjZJ4 7kfLlOIyCXly6IYdlgXB8fdm3XLycsBlk1eHVj2Tzj27463d8ALecUOnfR53wvfuOLgA JS5eRLAH/AN0VVw49cs1FPRPuCBAHioskkFcAVgKpZqO37V9a5UIhrH3o7ag3wKH44cq ZjjV93SovwyJCegTbYJVGVh5UEdHrUi/p+UobudhWxh77luD6E2xl7+Hv+SAtKqKYFJY wfF5A84Kn0Tp8DmFaWagojlSD747EMGe8mOLP2nIWRJRiAyDmYHUWcJDdAEpkeQgX6tD Ey+A== 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=MM014qTWc/BTbJIJ9XXkyJ6CD8+RdtKp2vlBJYzap2I=; fh=A+QcyawwK6Yq8daxuWFm+g/417ivXyGCFoP00qnMPro=; b=YtGmDnhV8PNNsAHqxc6MqPU4B60O3FpJ6lQICLw8NLfyB2xo4tEipKRT4NMqw3X+Mv I7+1m7INcy4AVtIvdy1jNdaZUY/LftRoaxlSZ0pUPte20DSqbkzYkvKgnD4BKYKPCzh6 3HWfLRr3aS/r7Golp77RNdsFav4tuurJmJ7TuRJV9vwBJX/Jp0uDrjaCqsjvVVLtbVdF dnDm0oKHuX0z7p532xCoB1ZrWp5AdcEOttBgf/mGZx5eDnDp29rG/aoz/YERRzK+Z8dI RkhOXiytqnTU9PgbomOZRAQMt9FTojjSrkfB1jmmQBTSoFp8iQOUiEPBt6PfBZmt3EB6 uTrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LSObHsKV; 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-173702-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u8-20020a170903124800b001e2a0f5c170si13015609plh.505.2024.05.08.11.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 11:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173702-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LSObHsKV; 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-173702-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173702-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B5BE3281E05 for ; Wed, 8 May 2024 18:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0B4712FF9C; Wed, 8 May 2024 18:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LSObHsKV" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 7F9BD12F5B1 for ; Wed, 8 May 2024 18:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715193012; cv=none; b=QBNuxBRsw/EEWxlO8dx2zHAi3mBIWPHU7tuCLKEWEX45Fp8DAvaSn/Bt9mC9pjv08ESi8ybs8NDs1DJqrB/9mnZJlvzKgIPfMeXVlVNxleVKsfTAeXsWk3rn9htFUvkHvkOpJZB8wmrpvQs040Oa50RC8NfF9Hx66dNAewQ2bs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715193012; c=relaxed/simple; bh=Ga3Ngyurh/GWTsaSz8bm6gGWfNz+qIwkdAIA/iJbJ4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ea35KrOGxGHuO2Y3j4FkmEN9mxON5M//+GWX5sRAkpI38gzZgLX2FGOsFDxtU1WBXTWHOukqu61JI7PEVqY2ZcBq7OtpW0e3UXLl+p8PYIvGa7yIQTca87QN5t7cij75QHWL+UgUrMN9FAUKmq7pTdgtQO9XCWSQXi3dz/zuX0k= 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=LSObHsKV; arc=none smtp.client-ip=170.10.133.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=1715193009; 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=MM014qTWc/BTbJIJ9XXkyJ6CD8+RdtKp2vlBJYzap2I=; b=LSObHsKVzywRoHHKDfmLjL2I7ijSZe1s0qI6Vmz9j3Qa8kkNhglLUhdaII4FgB+XG1BHDR 5/GCrPQVkx36WUgw65wA+fk30y1b3JweHyVocUCn2pQt2Jri7JJHUM1rA3VuyQovfWvsIG iq45UXr54IkCKDakwqgmf9fuMkObMLQ= 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-550-yI5SFXODOUWO93qE5vbptQ-1; Wed, 08 May 2024 14:30:03 -0400 X-MC-Unique: yI5SFXODOUWO93qE5vbptQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 91B7C380009B; Wed, 8 May 2024 18:30:02 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D3E010009E6; Wed, 8 May 2024 18:29:59 +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 v3 01/10] s390/uv: don't call folio_wait_writeback() without a folio reference Date: Wed, 8 May 2024 20:29:46 +0200 Message-ID: <20240508182955.358628-2-david@redhat.com> In-Reply-To: <20240508182955.358628-1-david@redhat.com> References: <20240508182955.358628-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.3 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.45.0