Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2035048ybb; Thu, 2 Apr 2020 11:50:08 -0700 (PDT) X-Google-Smtp-Source: APiQypIhRlWxo/O/AUx6NgZRHl1mxMgqyDevsTNJMyqMtrAiMQpCCPKPXW9iArLVl6ft7Y+MioRt X-Received: by 2002:aca:130d:: with SMTP id e13mr383990oii.98.1585853408617; Thu, 02 Apr 2020 11:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585853408; cv=none; d=google.com; s=arc-20160816; b=LGtPGhmpQzzkri8Jzgwb87bSDjgJXZTGThC7zFz3CslXlbwVkZQZqpxm0XOShb3Wfl zlCoWpg+iW2AEXwIhSO+XCm6gh+yCVYhXWzb1/Cof6YgarHA035CcxOFUu3yOSajn7y/ 94jkTjiSIVfLZGhUzqhLW6S/3+D2VNduLGvEap4E+Py13JMgVsIcIQZG8bNHfNhLE5xi vDjyjrBpNmHWluULgUbsETV+1LNbH3+D4NeTbiJu3Q84lFMaXYpUiA87RlqUzHd6KTUC xqROTH4pEIptCNoQYIMUl13f0jAgMuprd1W8WH0PUqcI9iS2bJ3p41NZ+KMBchL78R5T PPJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/TA1qIm6g7bOjJwF/S4q/AnUgMbYOhvn3awtkZe9/dU=; b=O8FT3Uw+acV7mEDc5v6pHTcqYRtD3mqJbDFCZnzqs8prVSnWWTQBwS3ABBtsDESAxL R4JRfI+VpFrU1GZEx1Xvo98eHPHLJX512Vag4E+a3HO/Ww5GVAsjDyJ3yMJbtz9MUaIU 1BF7pIetp2LBf73jC+PWohTYkIBXnupqy+SSp73A4XH1NsMJW+Hd7Cl5kR3Pq/ppLGTK R37qIsl24q77bkNPqTw0xBDSTlzZVG8jo7qaXmK8dhxXhQ1conpxSvJeUqOUJmBbjm7L uqVOZnRvJD2FFHNZoJI2FPCg+o/dBtAfEG/fje38+Imu/UH1ee0psF8Lo9bcr0/a51CT xRtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hkKARblD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d145si2553069oob.68.2020.04.02.11.49.55; Thu, 02 Apr 2020 11:50:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hkKARblD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390082AbgDBSsv (ORCPT + 99 others); Thu, 2 Apr 2020 14:48:51 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52881 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389923AbgDBSsg (ORCPT ); Thu, 2 Apr 2020 14:48:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585853315; 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=/TA1qIm6g7bOjJwF/S4q/AnUgMbYOhvn3awtkZe9/dU=; b=hkKARblDfnEQkJBePTHDiQ9rjQswJz+rEBl0rVMkgR8pF9qnf1f/ssu0+SIBAjjHRGugoe ESymxc7xA/SYhptFhcoUljMfjaLKZvira1n1czPz2AyJC+qNChfMdX8hv+jw4+o6cIgjOg FX8gggI0Ab2eXzebaI0x+OqVajhXUPI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-w-A29iO4NzGTkB53sIYlYw-1; Thu, 02 Apr 2020 14:48:33 -0400 X-MC-Unique: w-A29iO4NzGTkB53sIYlYw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 046971926DA0; Thu, 2 Apr 2020 18:48:32 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E3E860BF3; Thu, 2 Apr 2020 18:48:29 +0000 (UTC) From: David Hildenbrand To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Vasily Gorbik , Heiko Carstens , Cornelia Huck , Janosch Frank , Christian Borntraeger , David Hildenbrand Subject: [PATCH v1 3/5] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Date: Thu, 2 Apr 2020 20:48:17 +0200 Message-Id: <20200402184819.34215-4-david@redhat.com> In-Reply-To: <20200402184819.34215-1-david@redhat.com> References: <20200402184819.34215-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have to properly retry again by returning -EINVAL immediately in case somebody else instantiated the table concurrently. We missed to add the goto in this function only. The code now matches the other, similar shadowing functions. We are overwriting an existing region 2 table entry. All allocated pages are added to the crst_list to be freed later, so they are not lost forever. However, when unshadowing the region 2 table, we wouldn't trigge= r unshadowing of the original shadowed region 3 table that we replaced. It would get unshadowed when the original region 3 table is modified. As it'= s not connected to the page table hierarchy anymore, it's not going to get used anymore. However, for a limited time, this page table will stick around, so it's in some sense a temporary memory leak. Identified by manual code inspection. I don't think this classifies as stable material. Fixes: 998f637cc4b9 ("s390/mm: avoid races on region/segment/page table s= hadowing") Signed-off-by: David Hildenbrand --- arch/s390/mm/gmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c index f3dbc5bdde50..fd32ab566f57 100644 --- a/arch/s390/mm/gmap.c +++ b/arch/s390/mm/gmap.c @@ -1844,6 +1844,7 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long = saddr, unsigned long r3t, goto out_free; } else if (*table & _REGION_ENTRY_ORIGIN) { rc =3D -EAGAIN; /* Race with shadow */ + goto out_free; } crst_table_init(s_r3t, _REGION3_ENTRY_EMPTY); /* mark as invalid as long as the parent table is not protected */ --=20 2.25.1