Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2748115pxj; Mon, 31 May 2021 09:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTUZCcn73c+cC0isi2Togxpd31qvbjvvBwKCA8A1Voel5415gnKQn3Svi1MS12PcuS17j9 X-Received: by 2002:a17:906:ae91:: with SMTP id md17mr10475055ejb.433.1622479464917; Mon, 31 May 2021 09:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479464; cv=none; d=google.com; s=arc-20160816; b=erC2u8xTUoi8BQraKE/PAtGLnG8waZQMc4kokXMCxVYgV2+KsgHA/MX2Y8TZXBfB7l W8SAKj2jd0HLS2iscRoYBBVZpSDHXqz2wFRGkmI3nR5CGJOSP9UC4SCxlkSNBOd8q1hz YvuiLiClwHNbIipOwVdtsZejCPovoaRz69MauLsPA0ENysqwR9B5G5ypCDH1LRR1jhP/ LfayFjI0upfqwk9Z6x5nP1yftEycZxMVPNhpERDDmjcMesjGbO/jydCTm+fFZ5Egj+7t qtDGY0ZdIiveynR9+ZNSDLRUV/WR6oHHXa2FYXJbmpxAQlslodQshXLKxy2+Rm2U6KvO zd2w== 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=v/4/AHLy+zLt994KM2A4DQs5RoVTQVffBBzpdMd/Fmu6kFAnRiohG7vFpr5R7K5395 8A9hLj5rzWkisGpPMMumDtgbXKQj3kd/Vmlsa82z4vE/0lCnOqUCZZRk9rxNCgIDqAGm bXFHDdkbaakQk7Qk8ihDat4GY0SiHdL9s/C35Pm8TuwGUipbqOFFlDmYHZBk1keOxqBM ZIeqy8D6aofheDh1b3oIfRxpyILucAPieMClWliD1qhcyMnAxFMcvcIRM6KenB0C9JS/ dUGSD+m4g0QTNClPPjAhjq64ownZzeiM5Iu/VlGuS2luJgImZRRmX0nEcahNHpyUO+fz fo1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZiArtgy3; 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 y12si179548ejc.650.2021.05.31.09.44.02; Mon, 31 May 2021 09:44:24 -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=ZiArtgy3; 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 S234498AbhEaQoX (ORCPT + 99 others); Mon, 31 May 2021 12:44:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:47908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234040AbhEaOxQ (ORCPT ); Mon, 31 May 2021 10:53:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A0FD61CA6; Mon, 31 May 2021 13:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469522; bh=ZVRUcOSvAINhYD9WrYhTBPu86cPPOFC09xaeCR1Yfh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZiArtgy3O187sWQytPbgFiK6t62emdeyEnE9Y16kel2g2tv26sbDAdmXjkFUNsw2C i4HLRK3Q6r3leTQ8l5s0jDWaBHUeysqs5Q0p5hIacDIHR4xaFs1tqcA0xpMaRri5+S Vmr4Jk+CrMgWCxDjpw5Hsg2edBm6VMmweWvRq7rs= 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.12 229/296] vfio-ccw: Check initialized flag in cp_init() Date: Mon, 31 May 2021 15:14:44 +0200 Message-Id: <20210531130711.517434247@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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