Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6046572imd; Wed, 31 Oct 2018 06:08:43 -0700 (PDT) X-Google-Smtp-Source: AJdET5cUM1U6NUvGvqeBxw9TpfC5X45iDYm2Kis0lKaJKZAw29K37BEvhzQocnq0yaXer00sYner X-Received: by 2002:a62:39d2:: with SMTP id u79-v6mr3397088pfj.116.1540991323582; Wed, 31 Oct 2018 06:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540991323; cv=none; d=google.com; s=arc-20160816; b=VPARX6oGFATPuK1PDwVVoESdKiiZ0OEyPkYNwt77ue28srvGx5qh6dEBzuFmI/Cbox klkW6tIMChchUhvupCqxMRY82HAXTbUNlkXlU2/wIXq8VdLxY9af7kPU+hYcg4mwUL5K UYuKTkCO0qbGf6vQphTHv+2zEOJIbeNwprSt9weC71qTag1Ny//kHF2YNPMeoJy3yjDb ja3YVqsRKIaNmbI/3MiL/E2qZQXXxRRqiKlROJ6BSxQhw0UpKi8fS+Czo/54J3aoTg1G l41XQhhegGotsv6DADAYUIjI3TWwfVKyPc3bNHdQ/0WgZDdMzflzRNCC8OCt3dDfNGiv Oiew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rYL1xfEoMjlUN7I8XjGwv20e0mh4S3f2wabu/E5Oibg=; b=H6P45ZYlERbu4DWX1z5au0VZu3e/zNKx9x+GBQ33b5soF5UdSeFaxZy0/Qbq9TWnZL wKJrrYupbA/RMhaetIw1/0CG3iH6swKE7bds42wM5toPlIpcSWdt05ppIrNtR/OTe7ZQ 9UUO12i+ZRXQDTBl+yBa2XaC9UegVhV8M3+ijkmFJFcLnuJMIp9xJcxg2036SWYThh3a NB5I4Ym9/SKA2L4z3ueKyyDJRwMkbYFpb9tPw3umh308QWhzqDHXOvOqDPb+scZfl0Jd B+PxrxgDLySZ0sPQv3bCAXxh+M1j3d+jccfOuPsYPY5xiBu7jMddv0maIJQwoDcFobPK GSlA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b68-v6si27441762plb.398.2018.10.31.06.08.09; Wed, 31 Oct 2018 06:08:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729335AbeJaWFB (ORCPT + 99 others); Wed, 31 Oct 2018 18:05:01 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:55561 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729226AbeJaWFB (ORCPT ); Wed, 31 Oct 2018 18:05:01 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1gHqCx-0000m5-L7; Wed, 31 Oct 2018 14:06:51 +0100 Date: Wed, 31 Oct 2018 14:06:51 +0100 From: Kurt Kanzenbach To: David Miller Cc: anirudh@xilinx.com, John.Linn@xilinx.com, michal.simek@xilinx.com, radhey.shyam.pandey@xilinx.com, andrew@lunn.ch, yuehaibing@huawei.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] net: axienet: recheck condition after timeout in mdio_wait() Message-ID: <20181031130651.l4toezvyg4etevnh@linutronix.de> References: <20181030093139.10226-1-kurt@linutronix.de> <20181030093139.10226-2-kurt@linutronix.de> <20181030.112511.957438343014682098.davem@davemloft.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181030.112511.957438343014682098.davem@davemloft.net> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 30, 2018 at 11:25:11AM -0700, David Miller wrote: > From: Kurt Kanzenbach > Date: Tue, 30 Oct 2018 10:31:38 +0100 > > > The function could report a false positive if it gets preempted between reading > > the XAE_MDIO_MCR_OFFSET register and checking for the timeout. In such a case, > > the condition has to be rechecked to avoid false positives. > > > > Therefore, check for expected condition even after the timeout occurred. > > > > Signed-off-by: Kurt Kanzenbach > ... > > if (time_before_eq(end, jiffies)) { > > - WARN_ON(1); > > - return -ETIMEDOUT; > > + val = axienet_ior(lp, XAE_MDIO_MCR_OFFSET); > > + break; > > } > > + > > udelay(1); > > } > > - return 0; > > + if (val & XAE_MDIO_MCR_READY_MASK) > > + return 0; > > + > > + WARN_ON(1); > > + return -ETIMEDOUT; > > You are not fundamentally changing the situation at all. > > The condtion could change right after your last read of > XAR_MDIO_MCR_OFFSET, which is the same thing that happens before your > modifications to this code. That's true. The problem is different: If the current task gets preempted by a higher priority task between checking the condition and the timeout code, then a timeout might be falsely detected. Consider the following events: loop: check mdio condition ------------------------ task with real time priority may run for a long time ------------------------ check for timeout wait That's why I've added the recheck of the condition in the timeout case. > > It sounds more like the timeout is slightly too short, and that's the > real problem that causes whatever behavior you think you are fixing > here. The timeout value is not the problem here. Thanks, Kurt