Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp807384yba; Thu, 16 May 2019 09:11:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAxy6RJsVIONX0KJFM07Y973c8YQB6+ssbpaDbeSkTFPF0dUe5O4rjAT+zSlbrr75NwMAL X-Received: by 2002:a63:8741:: with SMTP id i62mr50864847pge.313.1558023116104; Thu, 16 May 2019 09:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558023116; cv=none; d=google.com; s=arc-20160816; b=mGmyeRGrJUUATzZJ08luZW0mzochysHs3zx1XFX77A5cK4LCB6q35nisxEomw5UF+t q0VGheubRZ7x4JnQ36hn5o9ZMAd4b2HiANiocncXnPtOO+xKpZXjmuOM/ZH2ZotJAokj BFrRgyvmjy/AYkIl+rhuD/pVTcXeFTLXlhLNUcvUGWepR5HBNjFPJSngybDpGGDj9zn2 jsD8DisfAsxib0miCzQZkUNQ5oWdAGpvjsfRjDFhaQpXsI/PdXoM+RVEbzrC11nmC4FF lnmWlLk0vXgNkrLJrsz93+4yQZGN2V/tXd9Vc4PzSxx6ajSB2LF2mOVh64sM7etcTjA6 ExRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bMHMBrMd0YNkJT0fsHTTWNRBFmrV68S4uDG6Stq2kXM=; b=xg7Gt12gVBRAUDe3UdaoR7cxABGZvDDTvwazz6g/gcY91OjzmaVacK9gTRBWgUTJOb DUb/PEz/zK0/ij08aKmbdT951DaKpz0dGDKObyICXijmFLlXVl45ROLmu4yS2+cWAHqK 0eeDk7tBHxoNUzmyX36IKdqEIgk+xnQSN8cZOYsuyFQgIfnABE1ORfvgpFoBoYmmOKpu a6QDTGsZZ4kBPZpmQrsdnV1bso3vVy/cpDbqMyd0yFcdorBAlzWoVniN/bBGIbDwsR1K Y6Rar7F7zbGsGAGMFjQAphwfsIsQz2mZUG7hi6EHr1ZwfwQCd76Iz1597C5kpvs8GOFo BoDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oQIJnd3c; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si5174318pgs.402.2019.05.16.09.11.38; Thu, 16 May 2019 09:11:56 -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=@google.com header.s=20161025 header.b=oQIJnd3c; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726829AbfEPQKM (ORCPT + 99 others); Thu, 16 May 2019 12:10:12 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:35367 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbfEPQKM (ORCPT ); Thu, 16 May 2019 12:10:12 -0400 Received: by mail-ot1-f66.google.com with SMTP id n14so3975259otk.2 for ; Thu, 16 May 2019 09:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bMHMBrMd0YNkJT0fsHTTWNRBFmrV68S4uDG6Stq2kXM=; b=oQIJnd3cJFOTGWU+mhqQw5xZ/48tAUVBLW2xsdnHW75CFgSaesak+3DGKJkRVnnlf5 f7vp8/QSuZL0RRyYca0jxJkcPCNSvi7RRnbKm5rO4uvFQinoZkfWxKegO3545xUKi6Tm yDlWfRiGkBs9X7KKIzePsKsJBYU4Mhp9dgLaLpepquR4TXbJgz+SyjP4Cb13IfAyCjJc yGAprbbVJ9x317dpUPRsbFj1RHmcJ2iqPoNfYLSKY45Sx4cye8fqfTTAzGmIRMznduug 6Zyh7c9l0qYmroDn3xiUT/EZlGqq0eanNec/JAobiVm74MfwZM1Br1PUonCZzlOV+vwq 1QHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bMHMBrMd0YNkJT0fsHTTWNRBFmrV68S4uDG6Stq2kXM=; b=kpnZloqW1GvPmGq4z+zzbJwfBo16ijk9Bi0FjfiqwOtYIKPNBpPP2S0AyAiCcEItBZ LBHjFf+gEWRuhF2vcjF4xO5Zi+4aGlDGyvkwKpe6r90zvzpeDLhnq3Iodo0dMPwQPJFX YKI5h3USRxdgmw2NW3GEaJuSpZTBGtqillJQjW1BjqlABFhG7S8AHzUQo+cwacnY06Wi 5EE3D52EJSB7j3eIJW61sHUgBhKh3glDx/d2iOWfpXfunHTOIFJxa5alShg8LcWlz2Ls ca8Pvrjjn6pL2nsLKYPs+AMmiXFS+gKEXlg0wRrVh35aD5oY6q6svIxDtHIBHuWZ1YY9 v0gA== X-Gm-Message-State: APjAAAVqBuVjTw/0/hnEMYoPUB/QR+50LB7lsnIQL2066f7YG76ak5Js Jp1Y9eDneL6DmOCQmBQe1eZ4xGdEUT//sFhLi4yAsQ== X-Received: by 2002:a9d:7347:: with SMTP id l7mr6367258otk.183.1558023010974; Thu, 16 May 2019 09:10:10 -0700 (PDT) MIME-Version: 1.0 References: <20190516094234.9116-1-oleksandr@redhat.com> <20190516094234.9116-5-oleksandr@redhat.com> <20190516142013.sf2vitmksvbkb33f@butterfly.localdomain> <20190516144323.pzkvs6hapf3czorz@butterfly.localdomain> In-Reply-To: <20190516144323.pzkvs6hapf3czorz@butterfly.localdomain> From: Jann Horn Date: Thu, 16 May 2019 18:09:44 +0200 Message-ID: Subject: Re: [PATCH RFC 4/5] mm/ksm, proc: introduce remote merge To: Oleksandr Natalenko Cc: kernel list , Kirill Tkhai , Hugh Dickins , Alexey Dobriyan , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Pavel Tatashin , Greg KH , Suren Baghdasaryan , Minchan Kim , Timofey Titovets , Aaron Tomlin , Grzegorz Halat , Linux-MM , Linux API Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 16, 2019 at 4:43 PM Oleksandr Natalenko wrote: > On Thu, May 16, 2019 at 04:20:13PM +0200, Oleksandr Natalenko wrote: > > > [...] > > > > @@ -2960,15 +2962,63 @@ static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns, > > > > static ssize_t madvise_write(struct file *file, const char __user *buf, > > > > size_t count, loff_t *ppos) > > > > { > > > > + /* For now, only KSM hints are implemented */ > > > > +#ifdef CONFIG_KSM > > > > + char buffer[PROC_NUMBUF]; > > > > + int behaviour; > > > > struct task_struct *task; > > > > + struct mm_struct *mm; > > > > + int err = 0; > > > > + struct vm_area_struct *vma; > > > > + > > > > + memset(buffer, 0, sizeof(buffer)); > > > > + if (count > sizeof(buffer) - 1) > > > > + count = sizeof(buffer) - 1; > > > > + if (copy_from_user(buffer, buf, count)) > > > > + return -EFAULT; > > > > + > > > > + if (!memcmp("merge", buffer, min(sizeof("merge")-1, count))) > > > > > > This means that you also match on something like "mergeblah". Just use strcmp(). > > > > I agree. Just to make it more interesting I must say that > > > > /sys/kernel/mm/transparent_hugepage/enabled > > > > uses memcmp in the very same way, and thus echoing "alwaysssss" or > > "madviseeee" works perfectly there, and it was like that from the very > > beginning, it seems. Should we fix it, or it became (zomg) a public API? > > Actually, maybe, the reason for using memcmp is to handle "echo" > properly: by default it puts a newline character at the end, so if we use > just strcmp, echo should be called with -n, otherwise strcmp won't match > the string. > > Huh? Ah, yes, other code like e.g. proc_setgroups_write() uses strncmp() and then has an extra check to make sure everything trailing is whitespace.