Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2680838pxj; Mon, 31 May 2021 08:07:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysNz7pYZRBXUqNTiPMZLQnjn6hVUFqAENMltFr4lJyNtJCLb3HwRrzur+LpGgJ+tvDkf1J X-Received: by 2002:a17:906:9258:: with SMTP id c24mr23439260ejx.101.1622473663963; Mon, 31 May 2021 08:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473663; cv=none; d=google.com; s=arc-20160816; b=pAraJQZwl1W5rZCocB0hzHlpd4gxv9jLczMP/mDIxwKkVKh71jKBrSo1u0TCR36Abv kpUGymOBzgzPwHy9sV/WojWWATbQmk7VXE5YWX7N/2FpWP6wa29V9FjLXednVTEXcD0/ P7Ai5RIARveatT/dBQg6JzmtxVLcBQjqdPj+gPEPS5yLDJ49/VwTb+vt8OusvA6qDX23 BZZ20Mr6MqrV7iMhTW5H6EzhwkloemEY0EzNDYzB3yJOeP/S7QyBKIAHLx40SQbVwj8A MJdKCvgmsgh06U33QCHgfa+w8Cg3rFan3hr/zWKgeUPLl1Mnhj1XSMutn2Qw9/gYzwEF /FxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ruyX1L86R5H7HckNEisQV20G1jaTDDw16svzhhRA19g=; b=fejog0TIC5SKTbFQAm6iyzhVGC/0yErJfN8rxWZKjPhXgYBzNElVPSLyqUlBn8Go5L nqnc+SBQBeYl+ICqMXnXyuaMPSjTiGati7n8+gQgvwWmmdQd1sZVI/UscDeY9or0OGVL /O5LOzaUsglRy9OhzdR0Zc4MeyUUDNYAHiRjr0Lb8pbKtxYwlJBak0b63GXDNBz+R0St DiYZ4KXWtH/jnmlmjPdkOM1PCQ19VlPFO5RbIjusv/voVo9t5l9hpSrE7eJFwPznh1Gc ZabwOFDBbt+L3Gqi7+Hc+kWh/RBs+479WFM7olV2GNYX1yV0/IHSv8chhRia8MnAWL2D kvwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fk2EfZEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h15si15395322ejq.124.2021.05.31.08.07.19; Mon, 31 May 2021 08:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fk2EfZEl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233339AbhEaPHo (ORCPT + 99 others); Mon, 31 May 2021 11:07:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233240AbhEaOJG (ORCPT ); Mon, 31 May 2021 10:09:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5BF761975; Mon, 31 May 2021 13:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468408; bh=ZVRUcOSvAINhYD9WrYhTBPu86cPPOFC09xaeCR1Yfh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fk2EfZElJuatrLZOcraQCzq/4VSlzjYJw9zzR4ifXDoCbt4mOpXFyVX9GhLjPXsZ8 gfeNmURyHfHPcK1smgAbvHuel5ve3b4V/Vm7lOhyuY0ghwxV7PbYEcvbJ8yuNj17CF Ojh642mxssRj466HVozh2WwZ6lrPiMJY+9QAy1WE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Farman , Cornelia Huck , Matthew Rosato , Sasha Levin Subject: [PATCH 5.10 196/252] vfio-ccw: Check initialized flag in cp_init() Date: Mon, 31 May 2021 15:14:21 +0200 Message-Id: <20210531130704.677269763@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Farman [ Upstream commit c6c82e0cd8125d30f2f1b29205c7e1a2f1a6785b ] We have a really nice flag in the channel_program struct that indicates if it had been initialized by cp_init(), and use it as a guard in the other cp accessor routines, but not for a duplicate call into cp_init(). The possibility of this occurring is low, because that flow is protected by the private->io_mutex and FSM CP_PROCESSING state. But then why bother checking it in (for example) cp_prefetch() then? Let's just be consistent and check for that in cp_init() too. Fixes: 71189f263f8a3 ("vfio-ccw: make it safe to access channel programs") Signed-off-by: Eric Farman Reviewed-by: Cornelia Huck Acked-by: Matthew Rosato Message-Id: <20210511195631.3995081-2-farman@linux.ibm.com> Signed-off-by: Cornelia Huck Signed-off-by: Sasha Levin --- drivers/s390/cio/vfio_ccw_cp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index b9febc581b1f..8d1b2771c1aa 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -638,6 +638,10 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 1); int ret; + /* this is an error in the caller */ + if (cp->initialized) + return -EBUSY; + /* * We only support prefetching the channel program. We assume all channel * programs executed by supported guests likewise support prefetching. -- 2.30.2